package com.desmond.squarecamera;

import ohos.app.Context;
import ohos.data.DatabaseHelper;
import ohos.data.preferences.Preferences;
import ohos.media.camera.params.Metadata;

public class CameraSettingPreferences {

    private static final String FLASH_MODE = "squarecamera__flash_mode";

    private static DatabaseHelper databaseHelper;

    private static Preferences getCameraSettingPreferences(Context context) {
        if (databaseHelper == null) {
            databaseHelper = new DatabaseHelper(context);
        }
        return databaseHelper.getPreferences("com.desmond.squarecamera");
    }

    public static void saveCameraFlashMode(Context context, int cameraFlashMode) {
        final Preferences preferences = getCameraSettingPreferences(context);

        if (preferences != null) {
            preferences.putInt(FLASH_MODE, cameraFlashMode);
            preferences.flush();
        }
    }

    public static int getCameraFlashMode(Context context) {
        final Preferences preferences = getCameraSettingPreferences(context);

        if (preferences != null) {
            return preferences.getInt(FLASH_MODE, Metadata.FlashMode.FLASH_AUTO);
        }

        return Metadata.FlashMode.FLASH_AUTO;
    }
}
